package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseSaleAttr;
import com.atguigu.gmall.model.product.BaseTrademark;
import com.atguigu.gmall.product.service.BaseTrademarkService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 钟涛
 * @version 1.0
 * @description: TODO
 * @date 2021/12/8 8:53
 */
@RequestMapping("/admin/product")
@RestController
public class BaseTrademarkController {
    @Autowired
    private BaseTrademarkService trademarkService;

    /**
     * 获取所有品牌
     */
    @RequestMapping("/baseTrademark/getTrademarkList")
    public Result getTrademark() {
        List<BaseTrademark> list = trademarkService.list();
        return Result.ok(list);
    }

    /**
     * 分页查询品牌
     * @param page
     * @param limit
     * @return
     */
    @GetMapping("/baseTrademark/{page}/{limit}")
    public Result getTrademarkPage(@PathVariable("page") Long page,
                                   @PathVariable("limit") Long limit) {
        Page<BaseTrademark> page1 = new Page<>(page, limit);
        Page<BaseTrademark> resultPage = trademarkService.page(page1);
        return Result.ok(resultPage);

    }

    /**
     * 保存品牌
     * /baseTrademark/save
     * @return
     */
    @PostMapping("/baseTrademark/save")
    public Result save(@RequestBody BaseTrademark baseTrademark) {
        trademarkService.save(baseTrademark);
        return Result.ok();
    }

    /**
     * 修改品牌
     * /baseTrademark/update
     * @return
     */
    @PutMapping("/baseTrademark/update")
    public Result update(@RequestBody BaseTrademark baseTrademark) {
        trademarkService.updateById(baseTrademark);
        return Result.ok();
    }

    /**
     * 删除品牌
     * /baseTrademark/remove/{id}
     * @return
     */
    @DeleteMapping("/baseTrademark/remove/{id}")
    public Result delete(@PathVariable("id") Long id) {
        trademarkService.removeById(id);
        return Result.ok();
    }

    /**
     * 根据指定id查出品牌
     * /baseTrademark/get/{id}
     * @return
     * http://192.168.200.1/admin/product/baseTrademark/get/2
     */
    @GetMapping("/baseTrademark/get/{id}")
    public Result getTrademarkById(@PathVariable("id") Long id) {
        BaseTrademark baseTrademark = trademarkService.getById(id);
        return Result.ok(baseTrademark);
    }

}
